package Fala;

/* Team Directories
 *
 * You are free to do whatever you want with this code. Frankly we don't give a damn.
 * 
 *  
 * Copyright GNU General Public License v3
 */

/**
 *
 * @author Gabriel
 */

import BuddyTemplate.QuestionFrame;
import BuddyTemplate.Question;
import BuddyTemplate.PictureFrame;
import BuddyTemplate.PictureChoiceFrame;
import BuddyTemplate.SaveGame;
import BuddyTemplate.QuestionLayerCollection;
import javax.swing.*;
import java.io.*;
import java.util.*;
        
public class Main implements StudyBuddy.RunnableBuddy{

    /**
     * @param args the command line arguments
     */
    
    String username;
    Integer thescore = new Integer(0);
    QuestionLayerCollection questions = new QuestionLayerCollection();
    
    public static void main(String[] args) {

        Main x = new Main();
        x.run();
        
    }
    
    public void run(){
        
        /* We Populate the QuestionCollection with questions*/
        Question<String, String> testquestion = new Question<String, String>();
        testquestion.setQuestion("How many roads must a man walk down?");
        testquestion.setDifficulty(99);
        testquestion.setChoice("12", false);
        testquestion.setChoice("22", false);
        testquestion.setChoice("16", true);
        testquestion.setChoice("None of the Above", false);
        
        questions.addQuestion(testquestion);
        
        Question<String, String> testquestion2 = new Question<String, String>();
        testquestion2.setQuestion("What's brown and sticky");
        testquestion2.setChoice("Poo", true);
        testquestion2.setChoice("A Stick", true);
        testquestion2.setChoice("Caramel", true);
        
        questions.addQuestion(testquestion2);
        
        // We simply use this to demonstrate how a non-standard question is handled
        
        Question<Object, Object> testquestion3 = new Question<Object, Object>();
        testquestion3.setQuestion("What is 1+1");
        testquestion3.setDifficulty(55);
        testquestion3.setChoice(new Integer(2), true);
        testquestion3.setChoice(new Integer(54), false);
        testquestion3.setChoice(new Integer(9999999), true);
        testquestion3.setChoice(new ImageIcon(getClass().getResource( "/Picture/Clouds.jpg")), false);
        
        questions.addQuestion(testquestion3);
        
        
        Question<String, ImageIcon> testquestion4 = new Question<String, ImageIcon>();
        testquestion4.setQuestion("Which one is a cloud");
        testquestion4.setDifficulty(0);
        testquestion4.setChoice(new ImageIcon(getClass().getResource( "/Picture/Clouds.jpg")), true);
        testquestion4.setChoice(new ImageIcon(getClass().getResource( "/Picture/Nature1.jpg")), false);
        testquestion4.setChoice(new ImageIcon(getClass().getResource( "/Picture/Nature2.jpg")), false);
        testquestion4.setChoice(new ImageIcon(getClass().getResource( "/Picture/Nature2.jpg")), false);
        
        questions.addQuestion(testquestion4);
        
        Question<ImageIcon, String> testquestion5 = new Question<ImageIcon, String>();
        testquestion5.setQuestion(new ImageIcon(getClass().getResource( "/Picture/Clouds.jpg")));
        testquestion5.setChoice("Marshmellow", false);
        testquestion5.setChoice("Cotton Candy", false);
        testquestion5.setChoice("Cloud", true);
        testquestion5.setChoice("None of the above", false);
       
        
        questions.addQuestion(testquestion5);
        
        // This is the rather inelegant pieces of code which get the Ball Rolling
   
        // First we increase the state of the question - we request the nextquestion 
       
        Question thenextquestion = questions.nextQuestion();
                
       
        
        // This is the rather inelegant pieces of code which get the Ball Rolling
   
        // First we increase the state of the question - we request the nextquestion 
       
        
        // Now depending on what question the first question is, we launch the appopriate window
        // Note that this same bit of code is also used in PictureFrame, PictureChoiceFrame, etc
        
        // We get the instance of the choice of the first method
        if(thenextquestion.choices.get(0) instanceof String && thenextquestion.getQuestion() instanceof String){
            QuestionFrame nextQuestion = new QuestionFrame(thescore, questions, thenextquestion);
            nextQuestion.setVisible(true);
        }
                
        else if(thenextquestion.choices.get(0) instanceof ImageIcon && thenextquestion.getQuestion() instanceof String){
            PictureFrame nextQuestion = new PictureFrame(thescore, questions, thenextquestion);
            nextQuestion.setVisible(true);
        }
                
        else if(thenextquestion.choices.get(0) instanceof String && thenextquestion.getQuestion() instanceof ImageIcon){
            PictureChoiceFrame nextQuestion = new PictureChoiceFrame(thescore, questions, thenextquestion);
            nextQuestion.setVisible(true);
        }
        
    }
    
    public String getName(){
        
        return "Rock Buddy";
        
    }
    
    public int getScore(){
       
        return SaveGame.score;
        
    }
    
    public void setLoginInfo(String theusername){
        
        username = theusername;
        
    }
    
    
    public Serializable getSavedGame(){
        
        return new SaveGame();
        
    }
    
    public void loadSavedGame(Serializable savegame){
        
        thescore = ((SaveGame)savegame).score;
        
    }
    
    

    

}
